package cate.game.role.farm.island.po;

import cate.common.table.farm.island.row.IslandGainRow;
import cate.game.GameBody;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "增益")
public class Gain {
    @NoteField(value = "增益id")
    public int gainId;

    @NoteField("胜利次数")
    public int winTime;

    public Gain(int gainId) {
        this.gainId = gainId;
    }

    public Gain() {}

    public IslandGainRow getRow(GameBody game){
        return game.table.island.gain.get(gainId);
    }

    public void onWin() {
        if (isLevelUpGain()) {
            winTime++;
        }
    }

    //胜利旌旗id
    private static final int FLAG_LEVEL_1 = 181;
    private static final int FLAG_LEVEL_2 = 182;
    private static final int FLAG_LEVEL_3 = 183;

    @JsonIgnore
    public boolean isLevelUpGain(){
        if (gainId == FLAG_LEVEL_1 || gainId == FLAG_LEVEL_2 || gainId == FLAG_LEVEL_3) {
            return true;
        }
        return false;
    }

    @JsonIgnore
    public int getAttrNum() {
        switch (gainId) {
            case FLAG_LEVEL_1:
                return Math.min(winTime, 3);
            case FLAG_LEVEL_2:
                return Math.min(winTime, 4);
            case FLAG_LEVEL_3:
                return Math.min(winTime, 5);
            default:
                return 0;
        }
    }
}
